<template>
  <div class="global">
    <div class="login_frame">
      <div class="logo">
        <img src="/header.jpg" alt="" srcset="" />
      </div>
      <div class="title">登录系统</div>
      <form class="form">
        <div>
          <input
            type="text"
            v-model="form.username"
            placeholder="请输入用户名"
          />
        </div>
        <div>
          <input
            type="password"
            v-model="form.password"
            placeholder="请输入密码"
          />
        </div>
      </form>
      <button class="button_group" @click="login">登录</button>

      <div class="register_point"></div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from "vue";
import { useRoute, useRouter } from "vue-router";

import { api_Login } from "../../api/api";

const Router = useRouter();

const form = reactive({
  username: "",
  password: "",
});
//登录
const login = () => {
  api_Login(form).then((res) => {
    if (res.data.code === 200) {
      ElMessage({
        message: res.data.msg,
        type: "success",
      });
      localStorage.setItem("token", res.data.data.token);
      localStorage.setItem("name", res.data.data.name);
      localStorage.setItem("username", res.data.data.username);
      localStorage.setItem("level", res.data.data.level);

      Router.push("/");
    } else {
      ElMessage.error(res.data.msg);
    }
  });
};
</script>

<style scoped>
.global {
  width: 100%;
  height: 100vh;
  background: url('LoginBlack.png') no-repeat;
  background-size:100% 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}
.login_frame {
  width: 560px;
  height: 680px;
  /* background-color: rgb(255, 255, 255); */
  background-color: #fff;
  opacity: 0.8;
  border-radius: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logo {
  margin-top: 80px;
  margin-bottom: 40px;
}
.logo img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}
.title {
  font-size: 32px;
  font-weight: 500;
}
.form {
  margin-top: 50px;
}

.form div {
  margin-bottom: 40px;
}

.form input {
  width: 300px;
  height: 60px;
  border-radius: 5px;
  border: 0px;
  box-shadow: 0px 0px 2px rgb(146, 146, 146);
  font-size: 24px;
  text-indent: 25px;
  color: #333;
  caret-color: rgb(146, 146, 146);
}
.form input:focus {
  outline: none;
  border: 0px;
  box-shadow: 0px 0px 2px rgb(16, 104, 236);
}
.button_group {
  width: 300px;
  height: 35px;
  font-size: 20px;
  border: none;
  border-radius: 35px;
  /* box-shadow: 0px 0px 5px rgb(21, 104, 228); */
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  background-color: black;
  color: #fff;
}

.button_group:hover {
  cursor: pointer;
}

.button_group:active {
  transform: scale(0.98);
}

.register_point {
  width: 300px;
  margin-top: 50px;
}
</style>
